(function (lib, config) {
    var loadFunc = function () {
        var textAry = config.words.split('|'), bgcolorAry = config.bgcolor.split('|'), textcolorAry = config.textcolor.split('|'), imglinkAry = config.imglink.split('|'), weblinkAry = config.weblink.split('|'), identiAry = config.identifier.split('|');
        textAry[0] = textAry[0] || '在线咨询';
        bgcolorAry[0] = bgcolorAry[0] || '#cd2a2b';
        textcolorAry[0] = textcolorAry[0] || '#ffffff';
        imglinkAry[0] = imglinkAry[0] || 'http://s3gfk.85613333.com/swt_gb/img/swt_bg.png';
        imglinkAry[1] = imglinkAry[1] || 'http://s3gfk.85613333.com/swt_gb/img/swt_btn.gif';
        weblinkAry[0] = weblinkAry[0] || 'tel:18032764591';
        identiAry[0] = identiAry[0] || 'swt_center';
        identiAry[1] = identiAry[1] || 'swt_right';
        function getScrollTop() {
            var scrollTop = 0;
            if (document.documentElement && document.documentElement.scrollTop) {
                scrollTop = document.documentElement.scrollTop;
            }
            else if (document.body) {
                scrollTop = document.body.scrollTop;
            }
            return scrollTop;
        }
        function getClientHeight() { //获取可视高度
            var clientHeight = 0;
            if (document.body.clientHeight && document.documentElement.clientHeight) {
                var clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
            }
            else {
                var clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
            }
            return clientHeight;
        }
        var _ua = navigator.userAgent, _ua_text = false, _position = "fixed";
        if (_ua.indexOf('baiduboxapp') > -1) {
            _ua_text = true; _position = "absolute";
        }
        config.width = 277, config.height = 222;
        var htmlStr = [];
        htmlStr.push("<style>");/*left:50%;top:50%;margin:-111px 0 0 -133.5px*/
        htmlStr.push("#box{width:277px;height:222px;position:" + _position + ";"+lib.util.getPosStyle(config)+";margin-left:30px;background:url(" + imglinkAry[0] + ") no-repeat;z-index:9999;display:none;}");
        htmlStr.push("#box img,#box2 img {border:0;}");
        htmlStr.push("#box span{display:block; width:50px; height:50px; position:absolute; top:60px;right:0;z-index:99999;}");
        htmlStr.push("#swt_center{width:277px;height:222px;background:url(" + imglinkAry[1] + ") no-repeat 16px 166px;}");
        htmlStr.push("#swt_center a{display:block;position:absolute;width:277px;height:222px;top:0;left:0;}");
        htmlStr.push("#swt_center a:nth-child(2){top:auto;left:auto;bottom:28px;right:28px;width:110px;height:30px;}");
        htmlStr.push("#box2{width:25px;height:90px;position:fixed;right:5px;top:30%;z-index:9999;display:none;}");
        htmlStr.push("#box2 a{display:block;width:25px;height:80px;background:" + bgcolorAry[0] + ";color:" + textcolorAry[0] + ";font-size:14px;text-align:center;line-height:20px;padding:5px 0;text-decoration:none;}");
        htmlStr.push("#LRdiv1,#LRdiv0{display:none!important;}");
        htmlStr.push("</style>");

        /***弹出***/
        htmlStr.push("<div id=\"box\" style=\"\">");/*top:50%;*/
        htmlStr.push("	<span><\/span>");
        htmlStr.push("	<div id=\"swt_center\">");
        htmlStr.push("		<a href=\"javascript:void(0);\" onclick=\"openZoosUrl(" + identiAry[0] + ");\" rel=\"nofollow\"><\/a>");
        htmlStr.push("		<a href=\"" + weblinkAry[0] + "\"><\/a>");
        htmlStr.push("	<\/div>");
        htmlStr.push("<\/div>");
        htmlStr.push("<div id=\"box2\">");
        htmlStr.push("	<a href=\"javascript:void(0);\" onclick=\"openZoosUrl(" + identiAry[1] + ");\" rel=\"nofollow\">" + textAry[0] + "<\/a> ");
        htmlStr.push("<\/div>")
        var o = document.createElement('div');
        o.innerHTML = htmlStr.join('');
        while (o.firstElementChild) {
            document.body.appendChild(o.firstElementChild);
        };

        setTimeout(level,config.firsttime*1000);
        function level() {
            var oBox = document.getElementById('box');
            var oH2 = oBox.getElementsByTagName('span')[0];
            var oBox2 = document.getElementById('box2');
            var oH22 = oBox2.getElementsByTagName('span')[0];
            oBox.style.display = 'block';
            oBox2.style.display = 'none';
            oH2.onclick = function () {
                oBox.style.display = 'none';
                oBox2.style.display = 'block';
                setTimeout(oBoxblock, config.relapsetime*1000);
            };
            if (config.eachtime > 0) setTimeout(oBoxblock,config.eachtime*1000);
        }

        function oBoxblock() {
            oBox = document.getElementById('box');
            oBox2 = document.getElementById('box2');
            oBox.style.display = 'block';
            oBox2.style.display = 'none';

        }

        function addEvent(obj, type, fn) {
            if (obj.attachEvent) {
                obj.attachEvent('on' + type, function () {
                    fn.call(obj);
                })
            } else {
                obj.addEventListener(type, fn, false);
            }
        }
        if (_ua_text) {
            var _t = document.getElementById('box').style.top;
            window.onscroll = function () {
                document.getElementById('box').style.top = parseInt(_t) + (getScrollTop() / getClientHeight()) * 100 + '%';
            }
        }

    };
    lib.load(loadFunc);
})('{{lib}}', '{{config}}');